package com.codebo.homiematch.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codebo.homiematch.common.BaseResponse;
import com.codebo.homiematch.common.ResultUtils;
import com.codebo.homiematch.model.dto.PostCommentRequest;
import com.codebo.homiematch.model.dto.PostCreateRequest;
import com.codebo.homiematch.model.dto.PostLikeStarRequest;
import com.codebo.homiematch.model.dto.PostListRequest;
import com.codebo.homiematch.model.vo.PostCommentVO;
import com.codebo.homiematch.model.vo.PostVO;
import com.codebo.homiematch.service.PostCommentService;
import com.codebo.homiematch.service.PostService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/post")
public class PostController
{
    @Resource
    private PostService postService;
    @Resource
    private PostCommentService postCommentService;

    @PostMapping("/list")
    public BaseResponse<Page<PostVO>> getPostList(PostListRequest postListRequest)
    {
        Page<PostVO> postList = postService.getPostList(postListRequest);
        return ResultUtils.success(postList);
    }

    @PostMapping("/create")
    public BaseResponse<String> createPost(@RequestBody PostCreateRequest postCreateRequest)
    {
        System.out.println("postCreateRequest = " + postCreateRequest);
        postService.createPost(postCreateRequest);
        return ResultUtils.success("qwq");
    }

    @PostMapping("/get")
    public BaseResponse<PostVO> getPost(Long id)
    {
        PostVO postVO = postService.getPost(id);
        return ResultUtils.success(postVO);
    }

    @PostMapping("/get/comment")
    public BaseResponse<List<PostCommentVO>> getPostCommentList(Long id)
    {
        List<PostCommentVO> postCommentVOList = postCommentService.getPostCommentList(id);
        return ResultUtils.success(postCommentVOList);
    }

    @PostMapping("/comment")
    public BaseResponse comment(PostCommentRequest postCommentRequest)
    {
        postCommentService.comment(postCommentRequest);
        return ResultUtils.success(null);
    }

    @PostMapping("/thumb")
    public BaseResponse thumb(@RequestBody PostLikeStarRequest postLikeStarRequest)
    {
        postService.thumb(postLikeStarRequest);
        return ResultUtils.success(null);
    }

    @PostMapping("/favour")
    public BaseResponse favor(@RequestBody PostLikeStarRequest postLikeStarRequest)
    {
        postService.favour(postLikeStarRequest);
        return ResultUtils.success(null);
    }

    @PostMapping("/thumb/status")
    public BaseResponse<Boolean> thumbStatus(@RequestBody PostLikeStarRequest postLikeStarRequest)
    {
        boolean status = postService.thumbStatus(postLikeStarRequest);
        return ResultUtils.success(status);
    }

    @PostMapping("/favour/status")
    public BaseResponse<Boolean> favorStatus(@RequestBody PostLikeStarRequest postLikeStarRequest)
    {
        boolean status = postService.favorStatus(postLikeStarRequest);
        return ResultUtils.success(status);
    }
}
